import os
import re
import pickle
import random
import time
import numpy as np
import redis
import threading
from threading import Thread

from config import *
from queue import PriorityQueue



def produce(r, name):
    while(True):
        time.sleep(random.random())
        r.rpush(name, random.randint(1,100))

def consume(r, name):
    while(True):
        # time.sleep(random.random())
        res = r.blpop(name)[1]
        print(res)
        print('---> %d' %int(res))

if __name__ == '__main__':
    pool = redis.ConnectionPool(host='127.0.0.1', db=5)  # 实现一个连接池

    r = redis.StrictRedis(connection_pool=pool, decode_responses=True)
    # r = redis.StrictRedis(host='127.0.0.1', decode_responses=True)


    # name = 'tmp'


    r.set('live',pickle.dumps([1,2,3]))

    a = r.get('live')
    print(a)
    print(type(pickle.loads(a)))



    # print(r.lpop('time'))

    # r.publish('boring','bbb')
    # r.publish('happy','hhh')



    # pub = r.pubsub()
    # pub.subscribe('boring')
    # a1 = pub.parse_response()

    # for i in pub.listen():
    #     print(i)




    # a2 = pub.parse_response()
    # print(a2)

    # print(r.lrange(name,0,-1))


    # t1 = Thread(target=produce, args=(r, name))
    # t2 = Thread(target=consume, args=(r, name))
    #
    #
    # t1.start()
    # t2.start()
    #
    # t1.join()
    # t2.join()










